﻿<%@ Page Title="" Language="VB" MasterPageFile="~/Master/Site.master" %>

<script runat="server">
    Private Sub Page_Init()
        UserRoles.DataSource = Roles.GetAllRoles()
        UserRoles.DataBind()
    End Sub

    Private Sub Page_PreRender()


        Dim allUsers As MembershipUserCollection = Membership.GetAllUsers()
        Dim filteredUsers As New MembershipUserCollection()

        If UserRoles.SelectedIndex > 0 Then
            Dim usersInRole As String() = Roles.GetUsersInRole(UserRoles.SelectedValue)
            For Each user As MembershipUser In allUsers
                For Each userInRole As String In usersInRole
                    If userInRole = user.UserName Then
                        filteredUsers.Add(user)
                        ' Breaks out of the inner foreach loop to avoid unneeded checking.
                        Exit For
                    End If
                Next
            Next
        Else
            filteredUsers = allUsers
        End If
        Users.DataSource = filteredUsers
        Users.DataBind()
    End Sub
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<!-- #include file="_nav.aspx -->

<table class="webparts">
<tr>
	<th>Users by Role</th>
</tr>
<tr>
<td class="details" valign="top">

<!-- #include file="_nav3.aspx -->

Role filter:

<asp:DropDownList ID="UserRoles" runat="server" AppendDataBoundItems="true" AutoPostBack="true">
<asp:ListItem>Show All</asp:ListItem>
</asp:DropDownList>


<br /><br />

<asp:GridView runat="server" ID="Users" AutoGenerateColumns="false"
	CssClass="list" AlternatingRowStyle-CssClass="odd"
	AllowSorting="true"
	>
<Columns>
	<asp:TemplateField>
		<HeaderTemplate>User Name</HeaderTemplate>
		<ItemTemplate>
		<a href="edit_user.aspx?username=<%# Eval("UserName") %>"><%# Eval("UserName") %></a>
		</ItemTemplate>
	</asp:TemplateField>
	<asp:BoundField DataField="email" HeaderText="Email" />
	<asp:BoundField DataField="comment" HeaderText="Comments" />
	<asp:BoundField DataField="creationdate" HeaderText="Creation Date" />
	<asp:BoundField DataField="lastlogindate" HeaderText="Last Login Date" />
	<asp:BoundField DataField="lastactivitydate" HeaderText="Last Activity Date" />
	<asp:BoundField DataField="isapproved" HeaderText="Is Active" />
	<asp:BoundField DataField="isonline" HeaderText="Is Online" />
	<asp:BoundField DataField="islockedout" HeaderText="Is Locked Out" />
</Columns>
</asp:GridView>

</td></tr></table>


</asp:Content>

